/*
 * @Author: szx
 * @Date: 2021-12-02 15:38:47
 * @LastEditTime: 2021-12-02 16:01:06
 * @Description:
 * @FilePath: \leetcode\500-599\506\506.js
 */

/**
 * @param {number[]} score
 * @return {string[]}
 */
// var findRelativeRanks = function (score) {
//     const n = score.length;
//     const desc = ['Gold Medal', 'Silver Medal', 'Bronze Medal'];
//     const arr = new Array(n).fill(0).map(() => new Array(2).fill(0));

//     for (let i = 0; i < n; ++i) {
//         arr[i][0] = score[i];
//         arr[i][1] = i;
//     }
//     arr.sort((a, b) => b[0] - a[0]);
//     const ans = new Array(n).fill(0);
//     for (let i = 0; i < n; ++i) {
//         if (i >= 3) {
//             ans[arr[i][1]] = '' + (i + 1);
//         } else {
//             ans[arr[i][1]] = desc[i];
//         }
//     }
//     return ans;
// };

var findRelativeRanks = function (score) {
    const map = new Map();
    const sortNums = [...score]
        .sort((a, b) => b - a)
        .forEach((num, index) => {
            map.set(num, index);
        });
    return score.map((item, index) => {
        if (map.get(item) == 0) {
            return 'Gold Medal';
        } else if (map.get(item) == 1) {
            return 'Silver Medal';
        } else if (map.get(item) == 2) {
            return 'Bronze Medal';
        }
        return map.get(item) + 1 + '';
    });
};

console.log(findRelativeRanks([1, 2, 35, 6, 8]));
